package com.usf.jprovider.schema.provider.random.number;

import javax.xml.bind.annotation.XmlAttribute;

import com.usf.jprovider.object.JObjectNode;
import com.usf.jprovider.object.env.Environment;
import com.usf.jprovider.object.type.JDouble;
import com.usf.jprovider.object.type.JType;
import com.usf.jprovider.schema.type.DBDouble;
import com.usf.jprovider.tools.RandomTools;

public final class DoubleRandom extends AbstractNumberRandomProvider{
	
	@XmlAttribute protected double min;
	@XmlAttribute protected double max;
	
	public DoubleRandom() {
		super();
		type = new DBDouble();
	}
	public double getMin() {
		return min;
	}
	public double getMax() {
		return max;
	}

	@Override
	public JDouble create(Environment env, JObjectNode node) {
		return new JDouble(RandomTools.randomizeDouble(min, max), type.getFormat());
	}
	@Override
	public boolean checkValue(Environment env, JObjectNode node, JType<?> value) {
		double number = ((JDouble)value).getValue(); 
		return (number >= min && number <= max);
	}
}
